package com.photographysharing.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data;

/**
 * @TableName statistics
 */
@TableName(value ="statistics")
@Data
public class Statistics implements Serializable {
    private String photoId;

    private Integer likeCount;

    private Integer watchCount;

    private Integer starCount;

    private static final long serialVersionUID = 1L;
    private Integer id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Statistics(String photoId, int likeCount, int watchCount, int starCount){
        setPhotoId(photoId);
        setStarCount(starCount);
        setWatchCount(watchCount);
        setLikeCount(likeCount);
        this.id = 0;
    }
    public Statistics(String photoId){
        setPhotoId(photoId);
        setLikeCount(0);
        setStarCount(0);
        setWatchCount(0);
    }
    public Statistics(){}

    public void increaseLike(){
        likeCount+=1;
    }
    public void reduceLike(){
        likeCount-=1;
    }
    public void increaseWatch(){watchCount+=1;}

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Statistics other = (Statistics) that;
        return (this.getPhotoId() == null ? other.getPhotoId() == null : this.getPhotoId().equals(other.getPhotoId()))
            && (this.getLikeCount() == null ? other.getLikeCount() == null : this.getLikeCount().equals(other.getLikeCount()))
            && (this.getWatchCount() == null ? other.getWatchCount() == null : this.getWatchCount().equals(other.getWatchCount()))
            && (this.getStarCount() == null ? other.getStarCount() == null : this.getStarCount().equals(other.getStarCount()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getPhotoId() == null) ? 0 : getPhotoId().hashCode());
        result = prime * result + ((getLikeCount() == null) ? 0 : getLikeCount().hashCode());
        result = prime * result + ((getWatchCount() == null) ? 0 : getWatchCount().hashCode());
        result = prime * result + ((getStarCount() == null) ? 0 : getStarCount().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", photoId=").append(photoId);
        sb.append(", likeCount=").append(likeCount);
        sb.append(", watchCount=").append(watchCount);
        sb.append(", starCount=").append(starCount);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}